% generate_trials_postitions_using_continous_trigger_channel
% This function uses an analog input (such as presure or froce grab sensor)
% which marks the beginning of the movement. It generates the postions of
% movements in the signal. Note that the sensor must be activated just
% before the actual movement. 

function [best_index,best_trigger] = generate_trials_postitions_using_continous_trigger_channel(trigger_channel)
    
scale = 5; % it is assumed that the values when activated are much bigger than the medium

ms = trigger_channel;

power  = (conv(ms'.^2,rectwin(1000)));
            
trigger = power > scale + median(power); %scaled added not multiplied

current_index = find(diff(trigger)==1);

best_index = current_index;
best_trigger = trigger;





